package com.cndw.kungfu.dao;

import java.util.List;

import com.cndw.dao.jade.Identity;
import com.cndw.dao.jade.annotation.DAO;
import com.cndw.dao.jade.annotation.SQL;
import com.cndw.dao.jade.annotation.SQLParam;
import com.cndw.kungfu.domain.Recharge;

@DAO
public interface IPayDao {

	public static final String TABLE = "kf_recharge";

	public static final String FIELDS = "id,playerId,accountName,playerName,transactionId,currency,inpourType,addcoin,money,gold,goldAll,exchangeType,depay,gDepay,createDate,state";

	@SQL("INSERT INTO "
			+ TABLE
			+ " ("
			+ FIELDS
			+ ") VALUES(0,:r.playerId,:r.accountName,:r.playerName,:r.transactionId,:r.currency,:r.inpourType,:r.addcoin,:r.money,:r.gold,:r.goldAll,:r.exchangeType,:r.depay,:r.gDepay,:r.createDate,:r.state)")
	public Identity insert(@SQLParam("r") Recharge recharge);

	@SQL("select sum(gold) from " + TABLE + " where playerId = :1 and exchangeType <> 2 ")
	public int selectPayGoldSum(long playerId);
	
	@SQL("select sum(gold) from " + TABLE + " where playerId = :1 and exchangeType=0 ")
	public int selectPayGoldSumOnlyQQPay(long playerId);	

	@SQL("SELECT COUNT(1) FROM " + TABLE + " WHERE transactionId=:1 and accountName=:2 ")
	public int selectOrderId(String transactionId,String accountName);
	
	//获取首冲
	@SQL("SELECT " + FIELDS + " FROM " + TABLE + " WHERE playerId=:1 and exchangeType <> 2 order by id asc limit 1")
	public Recharge selectFirst(long playerId);
	
	//获取充值记录
	@SQL("SELECT " + FIELDS + " FROM " + TABLE + " WHERE playerId=:1 and id>:2 and money>=10  and createDate>:3 and exchangeType <> 2 order by id asc limit 1")
	public Recharge selectRecharge(long playerId, int id, int activitybegintime);

	@SQL("select * from "
			+ TABLE
			+ "  where 1=1 #if(:playerId>0){and playerId=:playerId } #if(:transactionId){and transactionId=:transactionId } #if(:exchangeType>=0){and exchangeType=:exchangeType } #if(:beginTime>0){and createDate>:beginTime } #if(:endTime>0){and createDate<:endTime } order by createDate desc limit :offset,:limit")
	public List<Recharge> getRecharge(@SQLParam("playerId") long playerId, @SQLParam("transactionId") String transactionId,
			@SQLParam("exchangeType") int exchangeType, @SQLParam("beginTime") int beginTime, @SQLParam("endTime") int endTime, @SQLParam("offset") int offset,
			@SQLParam("limit") int limit);

	@SQL("select COUNT(*) from "
			+ TABLE
			+ "  where 1=1 #if(:playerId>0){and playerId=:playerId } #if(:transactionId){and transactionId=:transactionId } #if(:exchangeType>=0){and exchangeType=:exchangeType } #if(:beginTime>0){and createDate>:beginTime } #if(:endTime>0){and createDate<:endTime }")
	public int getRechargeCounts(@SQLParam("playerId") long playerId, @SQLParam("transactionId") String transactionId,
			@SQLParam("exchangeType") int exchangeType, @SQLParam("beginTime") int beginTime, @SQLParam("endTime") int endTime);
	
	//获取某段时间内的充值额度
	@SQL("select sum(gold) from " + TABLE + " where playerId=:1 and createDate>=:2 and createDate<=:3 and exchangeType <> 2 ")
	public int selectPeriodPaySum(long playerId, int beginTime, int endTime);
}
